﻿@{
    ViewBag.Title = "获取权限列表";
}
@section scripts
{
    <script type="text/javascript">
        $(function () {
            $("#editWindow").window('close');  // close a window  
            $("#tbList").datagrid({
                width: 'auto',
                height: 300,
                striped: true,
                fitColumns: true,
                singleSelect: true,
                url: '/Admin/Permission/GetPermissionList',
                queryParams: {},
                loadMsg: '数据加载中请稍后……',
                pagination: true,
                rownumbers: true,
                pageSize: 5,
                pageList:[5,10,20],
                columns: [[
                    { field: 'pid', title: 'ID', width: 100 },
                    { field: 'pName', title: '权限名', width: 100 },
                    { field: 'pAreaName', title: '区域名', width: 100 },
                    { field: 'pControllerName', title: '控制名', width: 100 },
                    { field: 'pActionName', title: '方法名', width: 100 },
                    { field: 'pParent', title: '父权限', width: 100 },
                    {
                        field: 'pFormMethod', title: '请求方式', width: 100, align: "center",
                        formatter: function (value) {
                            var requestType;
                            switch (value) {
                                case "1":
                                    requestType = "Get";
                                case "2":
                                    requestType = "Post";
                                default:
                                    requestType = "Both";
                            }
                            return requestType;
                        }
                    },
                    {
                        field: 'pOperationType', title: '操作类型', width: 100,
                        formatter: function (value) {
                            var operationType;
                            switch (value) {
                                case "0":
                                    operationType = "所有操作";
                                case "1":
                                    operationType = "EasyUI连接";
                                case "2":
                                    operationType = "打开新窗口";
                                default:
                                    operationType = "所有操作";
                            }
                            return operationType;
                        }
                    }
                ]],
                toolbar: [
                    {
                        iconCls: 'icon-add',
                        handler: function () {
                            //add function
                            $('#editWindow').window('open');  // open a window  
                            $("#editView").load("/admin/system/AddPermission");
                        }
                    }, '-', {
                        iconCls: 'icon-edit',
                        handler: function() {
                        //edit function
                        var selectRow = $("#tbList").datagrid("getSelected");
                        if (selectRow==null) {
                            $.messager.alert('警告', "请选择一行!");
                        } else {
                            $('#editWindow').window('open');  // open a window  
                            $("#editView").load("/admin/system/EditPermission/" + selectRow["pid"]);
                        }
                    }
                    }, '-', {
                        iconCls: 'icon-remove',
                        handler: function () {
                            //delete function
                            var selectRow = $("#tbList").datagrid("getSelected");
                            var index = $("#tbList").datagrid("getRowIndex", selectRow);
                            if (selectRow == null) {
                                $.messager.alert('警告', "请选择一行!");
                            } else {
                                $.post("/System/DeletePermission/" + selectRow["pid"], function (data) {
                                    $.ProcessMessage(data, function () {
                                        $("#tbList").datagrid("reload");
                                        $.messager.show({
                                            title: '提示',
                                            msg: '删除成功',
                                            timeout: 3000,
                                            showType: 'slide'
                                        });
                                    });
                                });
                            }
                        }
                    }, '-', {
                        iconCls: 'icon-search',
                        handler: function () {
                            //查看子权限
                            var selectRow = $("#tbList").datagrid("getSelected");
                            if (selectRow == null) {
                                $.alertMsg('请选择一行!');
                            } else {
                                $('#tbList').datagrid('load', {
                                    parendId: selectRow["pid"]
                                });
                            }
                        }
                    }, '-', {
                        iconCls: 'icon-undo',
                        handler: function () {
                            //返回主权限
                            $('#tbList').datagrid('load', {
                                parendId: 1
                            });
                        }
                    }, '-',{
                        iconCls: 'icon-sum',
                        handler: function () {
                            $('#tbList').datagrid('load', {
                                parendId: 10000
                            });
                        }
                    }, '-', {
                    iconCls: 'icon-reload',
                    handler: function() {
                        $('#tbList').datagrid('reload');
                    }
                    }
                ]

            });

            //initModifyForm();
        })
    </script>
   
}

<table id="tbList" style="height: 100%;width: 100%"></table>
<div id="editWindow" class="easyui-window" title="My Window" style="width:600px;height:400px"
     data-options="iconCls:'icon-save',modal:true">
    <div id="editView"></div>
</div>  